unit Class_Unit;


interface
uses
  Classes,SysUtils,DB,Uni,UniEngine;

type
  TUNIT=class(TUniEngine)
  private
    FUNITLINK : string;
    FUNITCODE : string;
    FUNITNAME : string;
    FUNITCALL : string;
    FUNITADDR : string;
    FUNITKIND : string;
    FUNITLEVL : Integer;
    FUNITPREV : string;
    FUNITMEMO : string;
    FUNITABBR : string;
    FUNITIDEX : Integer;
    FUNITORDR : Integer;
  protected
    procedure SetParameters;override;
    function  GetStrInsert:string;override;
    function  GetStrUpdate:string;override;
    function  GetStrDelete:string;override;
  public
    function  GetStrsIndex:string;override;
  public
    //#function  GetNextIndx:Integer;overload;
    //#function  GetNextIndx(AUniConnection:TUniConnection):Integer;overload;
  public
    function  CheckExist(AUniConnection:TUniConnection):Boolean;override;
  public
    destructor  Destroy; override;
    constructor Create;
  published
    property UNITLINK : string read FUNITLINK  write FUNITLINK;
    property UNITCODE : string read FUNITCODE  write FUNITCODE;
    property UNITNAME : string read FUNITNAME  write FUNITNAME;
    property UNITCALL : string read FUNITCALL  write FUNITCALL;
    property UNITADDR : string read FUNITADDR  write FUNITADDR;
    property UNITKIND : string read FUNITKIND  write FUNITKIND;
    property UNITLEVL : Integer read FUNITLEVL  write FUNITLEVL;
    property UNITPREV : string read FUNITPREV  write FUNITPREV;
    property UNITMEMO : string read FUNITMEMO  write FUNITMEMO;
    property UNITABBR : string read FUNITABBR  write FUNITABBR;
    property UNITIDEX : Integer read FUNITIDEX  write FUNITIDEX;
    property UNITORDR : Integer read FUNITORDR  write FUNITORDR;
  public
    class function  ReadDS(AUniQuery:TUniQuery):TUniEngine;override;
    class procedure ReadDS(AUniQuery:TUniQuery;var Result:TUniEngine);override;
    class function  CopyIt(AUNIT:TUNIT):TUNIT;overload;
    class procedure CopyIt(AUNIT:TUNIT;var Result:TUNIT);overload;
  end;

implementation

{ TUNIT }
procedure TUNIT.SetParameters;
begin
  inherited;
  with FUniSQL.Params do
  begin
    case FOptTyp of
      otAddx:
      begin
        ParamByName('UNIT_LINK').Value := UNITLINK;
        ParamByName('UNIT_CODE').Value := UNITCODE;
        ParamByName('UNIT_NAME').Value := UNITNAME;
        ParamByName('UNIT_CALL').Value := UNITCALL;
        ParamByName('UNIT_ADDR').Value := UNITADDR;
        ParamByName('UNIT_KIND').Value := UNITKIND;
        ParamByName('UNIT_LEVL').Value := UNITLEVL;
        ParamByName('UNIT_PREV').Value := UNITPREV;
        ParamByName('UNIT_MEMO').Value := UNITMEMO;
        ParamByName('UNIT_ABBR').Value := UNITABBR;
        ParamByName('UNIT_IDEX').Value := UNITIDEX;
        ParamByName('UNIT_ORDR').Value := UNITORDR;
      end;
      otEdit:
      begin
        ParamByName('UNIT_LINK').Value := UNITLINK;
        ParamByName('UNIT_CODE').Value := UNITCODE;
        ParamByName('UNIT_NAME').Value := UNITNAME;
        ParamByName('UNIT_CALL').Value := UNITCALL;
        ParamByName('UNIT_ADDR').Value := UNITADDR;
        ParamByName('UNIT_KIND').Value := UNITKIND;
        ParamByName('UNIT_LEVL').Value := UNITLEVL;
        ParamByName('UNIT_PREV').Value := UNITPREV;
        ParamByName('UNIT_MEMO').Value := UNITMEMO;
        ParamByName('UNIT_ABBR').Value := UNITABBR;
        ParamByName('UNIT_IDEX').Value := UNITIDEX;
        ParamByName('UNIT_ORDR').Value := UNITORDR;
      end;
      otDelt:
      begin
        ParamByName('UNIT_LINK').Value := UNITLINK;

      end;
    end;
  end;
end;

function TUNIT.CheckExist(AUniConnection: TUniConnection): Boolean;
begin
  Result:=CheckExist('TBL_UNIT',['UNIT_LINK',UNITLINK],AUniConnection);
end;

{#function TUNIT.GetNextIndx: Integer;
begin

end;}

{#function TUNIT.GetNextIndx(AUniConnection: TUniConnection): Integer;
begin

end;}

function TUNIT.GetStrDelete: string;
begin
  Result:='DELETE FROM TBL_UNIT WHERE   UNIT_LINK=:UNIT_LINK';
end;

function TUNIT.GetStrInsert: string;
begin
  Result:='INSERT INTO TBL_UNIT'
         +'    ( UNIT_LINK, UNIT_CODE, UNIT_NAME, UNIT_CALL, UNIT_ADDR'
         +'    , UNIT_KIND, UNIT_LEVL, UNIT_PREV, UNIT_MEMO, UNIT_ABBR'
         +'    , UNIT_IDEX, UNIT_ORDR)'
         +'    VALUES'
         +'    (:UNIT_LINK,:UNIT_CODE,:UNIT_NAME,:UNIT_CALL,:UNIT_ADDR'
         +'    ,:UNIT_KIND,:UNIT_LEVL,:UNIT_PREV,:UNIT_MEMO,:UNIT_ABBR'
         +'    ,:UNIT_IDEX,:UNIT_ORDR)';
end;

function TUNIT.GetStrsIndex: string;
begin
  Result:=Format('%S',[UNITLINK]);
end;

function TUNIT.GetStrUpdate: string;
begin
  Result:='UPDATE  TBL_UNIT SET'
         +'    UNIT_CODE=:UNIT_CODE,'
         +'    UNIT_NAME=:UNIT_NAME,'
         +'    UNIT_CALL=:UNIT_CALL,'
         +'    UNIT_ADDR=:UNIT_ADDR,'
         +'    UNIT_KIND=:UNIT_KIND,'
         +'    UNIT_LEVL=:UNIT_LEVL,'
         +'    UNIT_PREV=:UNIT_PREV,'
         +'    UNIT_MEMO=:UNIT_MEMO,'
         +'    UNIT_ABBR=:UNIT_ABBR,'
         +'    UNIT_IDEX=:UNIT_IDEX,'
         +'    UNIT_ORDR=:UNIT_ORDR'
         +'    WHERE UNIT_LINK=:UNIT_LINK';
end;

constructor TUNIT.Create;
begin

end;

destructor TUNIT.Destroy;
begin

  inherited;
end;

class function TUNIT.ReadDS(AUniQuery: TUniQuery): TUniEngine;
begin
  Result:=TUNIT.Create;
  TUNIT.ReadDS(AUniQuery,Result);
end;

class procedure TUNIT.ReadDS(AUniQuery: TUniQuery; var Result: TUniEngine);
var
  I:Integer;
  Field:TField;
  FieldName:string;
begin
  if Result=nil then Exit;

  with TUNIT(Result) do
  begin
    for I:=0 to AUniQuery.Fields.Count-1 do
    begin
      Field:=AUniQuery.Fields.Fields[I];
      //if field.fieldname is not all uppercase,please use uppercase().
      FieldName:=UpperCase(Field.FieldName);
      if FieldName='UNIT_LINK' then
      begin
        UNITLINK :=Field.AsString;
      end else
      if FieldName='UNIT_CODE' then
      begin
        UNITCODE :=Field.AsString;
      end else
      if FieldName='UNIT_NAME' then
      begin
        UNITNAME :=Field.AsString;
      end else
      if FieldName='UNIT_CALL' then
      begin
        UNITCALL :=Field.AsString;
      end else
      if FieldName='UNIT_ADDR' then
      begin
        UNITADDR :=Field.AsString;
      end else
      if FieldName='UNIT_KIND' then
      begin
        UNITKIND :=Field.AsString;
      end else
      if FieldName='UNIT_LEVL' then
      begin
        UNITLEVL :=Field.AsInteger;
      end else
      if FieldName='UNIT_PREV' then
      begin
        UNITPREV :=Field.AsString;
      end else
      if FieldName='UNIT_MEMO' then
      begin
        UNITMEMO :=Field.AsString;
      end else
      if FieldName='UNIT_ABBR' then
      begin
        UNITABBR :=Field.AsString;
      end else
      if FieldName='UNIT_IDEX' then
      begin
        UNITIDEX :=Field.AsInteger;
      end else
      if FieldName='UNIT_ORDR' then
      begin
        UNITORDR :=Field.AsInteger;
      end;
    end
  end;
end;

class function  TUNIT.CopyIt(AUNIT: TUNIT): TUNIT;
begin
  Result:=TUNIT.Create;
  TUNIT.CopyIt(AUNIT,Result)
end;

class procedure TUNIT.CopyIt(AUNIT:TUNIT;var Result:TUNIT);
begin
  if Result=nil then Exit;
  Result.UNITLINK :=AUNIT.UNITLINK;
  Result.UNITCODE :=AUNIT.UNITCODE;
  Result.UNITNAME :=AUNIT.UNITNAME;
  Result.UNITCALL :=AUNIT.UNITCALL;
  Result.UNITADDR :=AUNIT.UNITADDR;
  Result.UNITKIND :=AUNIT.UNITKIND;
  Result.UNITLEVL :=AUNIT.UNITLEVL;
  Result.UNITPREV :=AUNIT.UNITPREV;
  Result.UNITMEMO :=AUNIT.UNITMEMO;
  Result.UNITABBR :=AUNIT.UNITABBR;
  Result.UNITIDEX :=AUNIT.UNITIDEX;
  Result.UNITORDR :=AUNIT.UNITORDR;
end;

end.

